import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:qaun_ni_dev/model/report_model.dart';
import 'package:qaun_ni_dev/utils/request.dart';
import 'package:qaun_ni_dev/utils/toast.dart';


class ReportProvider with ChangeNotifier {

  int page = 1;
  List<ReportData> reportListData = [];

  getReportList(context) async{
    page = 1;
    reportListData = [];
    var formData = {
      'currentPage': page
    };
    await requestPost(context, '/check/reportList',formData: formData).then((value){
      var res = json.decode(value.toString());
      print(res);
      var tempData = ReportModel.fromJson(res);
      reportListData = tempData.data;
    });
    notifyListeners();

  }


  getReportMoreList(context) async{
    page++;
    var formData = {
      'currentPage': page
    };
    await requestPost(context, '/check/reportList',formData: formData).then((value){
      var res = json.decode(value.toString());
      print(res);
      var tempData = ReportModel.fromJson(res);
      if(tempData.code == 200) {
        var tempMoreData = tempData.data;
        if(tempMoreData.length > 0 ) {
          reportListData.addAll(tempMoreData);
        } else {
          Toast.toast(context,msg: '已经没有更多数据了哦！');
        }
      }
    });
    notifyListeners();

  }

  // 审阅
  reviewReport(context,userId) async{
    var formData = {
      'reportId': userId
    };
    await requestPost(context, '/check/reportResolve',formData: formData).then((value){
      var res = json.decode(value.toString());
      if(res['code'] == 200) {
        Toast.toast(context,msg: '您已经审查该举报');
      } else {
        Toast.toast(context,msg: '操作出错');
      }
    });
  }



}